package com.bdqn.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdqn.mapper.RightMapper;
import com.bdqn.pojo.Right;
import com.bdqn.service.RightService;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * 权限Service实现
 *
 * @author LILIBO
 * @since 2024/09/07
 */
@Service
public class RightServiceImpl extends ServiceImpl<RightMapper, Right> implements RightService {

    @Resource
    private RightMapper rightMapper;

    /**
     * 获取所有权限信息
     *
     * @return
     */
    @Override
    @Cacheable(value = "right", key = "'all'", unless = "#result==null")
    public List<Right> findAll() {
        return super.list();
    }

    /**
     * 根据角色ID获取权限集合
     *
     * @param roleId
     * @return
     */
    @Override
    @Cacheable(value = "right", key = "'roleId:'+#roleId", condition = "#roleId != null", unless = "#result==null")
    public Set<Right> findRightByRoleId(Long roleId) {
        return rightMapper.findRightByRoleId(roleId);
    }

}




